LOCAL_DIR := $(GET_LOCAL_DIR)

MODULE := $(LOCAL_DIR)

# ROMBASE, MEMBASE, and MEMSIZE are required for the linker script
ROMBASE := 0x00000000
MEMBASE := 0x1FFF8000
# default memsize, specific HC32_CHIP may override this
# and target/project may have already overridden
MEMSIZE := 192512

ARCH := arm
ARM_CPU := cortex-m4

# TODO: integrate better with platform/hc32f46x/CMSIS/hc32f46x.h
ifeq ($(HC32_CHIP),hc32f460)
GLOBAL_DEFINES += HC32F46x
FOUND_CHIP := true
endif

ifeq ($(FOUND_CHIP),)
$(error unknown HC32F46x chip $(HC32_CHIP))
endif

GLOBAL_DEFINES += \
	USE_DEVICE_DRIVER_LIB \
	MEMSIZE=$(MEMSIZE)

GLOBAL_INCLUDES += \
	$(LOCAL_DIR)/include/dev

MODULE_SRCS += \
	$(LOCAL_DIR)/init.c \
	$(LOCAL_DIR)/vectab.c \
	$(LOCAL_DIR)/gpio.c \
	$(LOCAL_DIR)/timer.c \
	$(LOCAL_DIR)/debug.c \
	$(LOCAL_DIR)/swdt.c \
	$(LOCAL_DIR)/uart.c

# use a two segment memory layout, where all of the read-only sections 
# of the binary reside in rom, and the read/write are in memory. The 
# ROMBASE, MEMBASE, and MEMSIZE make variables are required to be set 
# for the linker script to be generated properly.
#
LINKER_SCRIPT += \
	$(BUILDDIR)/system-twosegment.ld

MODULE_DEPS += \
	platform/hc32f46x/CMSIS \
	platform/hc32f46x/hc32f46x_ddl_Rev1.3.0 \
	arch/arm/arm-m/systick \
	lib/cbuf \
	lib/bio

include make/module.mk
